﻿@model ProductModel.ProductAttributeMappingModel
@{
    Layout = "";
    //page title
    ViewBag.Title = Loc["Admin.Catalog.Products.ProductAttributes.Details"];
}
<form id="ProductAttributeMappingPopup" asp-area="@Constants.AreaAdmin" asp-controller="Product" asp-action="ProductAttributeMappingPopup" enctype="multipart/form-data" method="post"
      asp-route-ProductId="@HtmlExtensions.HtmlEncodeSafe(Context.Request.Query["ProductId"])"
      asp-route-productAttributeMappingId="@HtmlExtensions.HtmlEncodeSafe(Context.Request.Query["ProductAttributeMappingId"])"
      asp-route-btnId="@HtmlExtensions.HtmlEncodeSafe(Context.Request.Query["btnId"])"
      asp-route-formId="@HtmlExtensions.HtmlEncodeSafe(Context.Request.Query["formId"])">


    <div asp-validation-summary="All"></div>
    <input asp-for="ProductId" type="hidden"/>
    <input asp-for="Id" type="hidden"/>

    <div class="row">
        <div class="col-md-12">
            <div class="x_panel light form-fit">
                <div class="x_title">
                    <div class="caption">
                        <i class="fa fa-cubes"></i>
                        @if (string.IsNullOrEmpty(Model.Id))
                        {
                            <text> @Loc["Admin.Catalog.Products.ProductAttributes.AddNew"]</text>
                        }
                        else
                        {
                            <text>@Loc["Admin.Catalog.Products.ProductAttributes.Edit"]</text>
                        }
                    </div>
                </div>
                <div class="x_content form">
                    <div class="form-horizontal">
                        <div class="form-body">
                            <div class="form-group">
                                <admin-label asp-for="ProductAttribute"/>
                                <div class="col-md-9 col-sm-9">
                                    <admin-select asp-for="ProductAttributeId" asp-items="Model.AvailableProductAttribute"/>
                                    <span asp-validation-for="ProductAttributeId"></span>
                                </div>
                            </div>
                            <div class="form-group">
                                <admin-label asp-for="TextPrompt"/>
                                <div class="col-md-9 col-sm-9">
                                    <admin-input asp-for="TextPrompt"/>
                                    <span asp-validation-for="TextPrompt"></span>
                                </div>
                            </div>
                            <div class="form-group">
                                <admin-label asp-for="IsRequired" class="col-sm-3 control-label"/>
                                <div class="col-md-9 col-sm-9">
                                    <label class="mt-checkbox mt-checkbox-outline control control-checkbox">
                                        <admin-input asp-for="IsRequired"/>
                                        <div class="control__indicator"></div>
                                    </label>
                                    <span asp-validation-for="IsRequired"></span>
                                </div>
                            </div>
                            <div class="form-group">
                                <admin-label asp-for="ShowOnCatalogPage" class="col-sm-3 control-label"/>
                                <div class="col-md-9 col-sm-9">
                                    <label class="mt-checkbox mt-checkbox-outline control control-checkbox">
                                        <admin-input asp-for="ShowOnCatalogPage"/>
                                        <div class="control__indicator"></div>
                                    </label>
                                    <span asp-validation-for="ShowOnCatalogPage"></span>
                                </div>
                            </div>
                            <div class="form-group">
                                <admin-label asp-for="AttributeControlType"/>
                                <div class="col-md-9 col-sm-9">
                                    <admin-select asp-for="AttributeControlTypeId" asp-items="EnumTranslationService.ToSelectList(Model.AttributeControlTypeId, valuesToExclude: [(int)AttributeControlType.Hidden])"/>
                                    <span asp-validation-for="AttributeControlTypeId"></span>
                                </div>
                            </div>
                            <div class="form-group">
                                <admin-label asp-for="Combination" class="col-sm-3 control-label"/>
                                <div class="col-md-9 col-sm-9">
                                    <label class="mt-checkbox mt-checkbox-outline control control-checkbox">
                                        <admin-input asp-for="Combination"/>
                                        <div class="control__indicator"></div>
                                    </label>
                                    <span asp-validation-for="Combination"></span>
                                </div>
                            </div>
                            <div class="form-group">
                                <admin-label asp-for="DisplayOrder"/>
                                <div class="col-md-9 col-sm-9">
                                    <admin-input asp-for="DisplayOrder"/>
                                    <span asp-validation-for="DisplayOrder"></span>
                                </div>
                            </div>
                            <div class="form-group">
                                <div class="offset-sm-3 offset-md-3 col-md-9 col-sm-9">
                                    <button class="btn btn-success" type="submit" name="save">
                                        <i class="fa fa-check"></i> @Loc["Admin.Common.Save"]
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script>
        var mfp = $.magnificPopup.instance;
        $("#ProductAttributeMappingPopup").submit(function (e) {
            e.preventDefault();
            var form = $(this);
            var url = form.attr('action');
            $.ajax({
                type: "POST",
                url: url,
                data: form.serialize(),
                success: function (data) {
                    if (data == "") {
                        mfp.close();
                        $('#btnRefreshProductAttributes').click();
                    } else {
                        $.magnificPopup.open({
                            items: {
                                src: data,
                                type: 'inline'
                            },
                            callbacks: {
                                open: function () {
                                    $('.mfp-wrap').removeAttr('tabindex');
                                }
                            }
                        });
                    }
                }
            });
        });
    </script>
</form>